<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<canvas id="canvas"></canvas>
    <button class="button-balanced" id="save">save
        <a href="" download="canvas_love.png" id="save_href">
            <img src="" id="save_img"/>
<script>
    var c=document.getElementById("canvas");
    function drawLove(canvas){
        let ctx = canvas.getContext("2d");
        ctx.beginPath();
        ctx.fillStyle="#E992B9";
        ctx.moveTo(75,40);
        ctx.bezierCurveTo(75,37,70,25,50,25);
        ctx.bezierCurveTo(20,25,20,62.5,20,62.5);
        ctx.bezierCurveTo(20,80,40,102,75,120);
        ctx.bezierCurveTo(110,102,130,80,130,62.5);
        ctx.bezierCurveTo(130,62.5,130,25,100,25);
        ctx.bezierCurveTo(85,25,75,37,75,40);
        ctx.fill();
    }
    drawLove(c);

    var butSave = document.getElementById("save");
    butSave.onclick=function(){
        var svaeHref = document.getElementById("save_href");
        /*
         21
         * 传入对应想要保存的图片格式的mime类型
         22
         * 常见：image/png，image/gif,image/jpg,image/jpeg
         23
         */
        var img = document.getElementById("save_img");
        var tempSrc = canvas.toDataURL("image/png");
        svaeHref.href=tempSrc;
        img.src=tempSrc;
    };
</script>
</body>
</html>